import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport'
import { Project } from 'src/interface/project.interface';
import { ProjectService } from './project.service';

@Controller('project')
@ApiTags('项目模块')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth('jwt')
export class ProjectController {
  constructor(private readonly projectService: ProjectService) { }

  @Post('create')
  @ApiOperation({
    summary: '新增项目'
  })
  addProject(@Body() project: Project) {
    return this.projectService.createProject(project)
  }

  @Post('delete/:id')
  @ApiOperation({
    summary: '删除项目'
  })
  removeProject(@Param('id') projectId: string) {
    return this.projectService.deleteProject(projectId)
  }

  @Post('alter/:id')
  @ApiOperation({
    summary: '修改项目'
  })
  changeProject(@Param('id') projectId: string, @Body() project: Project) {
    return this.projectService.alterProject(projectId, project)
  }

  @Post('find/:id')
  @ApiOperation({
    summary: '按id查询项目'
  })
  findProject(@Param('id') projectId: string) {
    return this.projectService.findProjectById(projectId)
  }

  @Get('projects/:userId/:page')
  @ApiOperation({
    summary: '根据用户id获取项目'
  })
  getProjects(@Param('userId') userId: string, @Param('page') page:number){
    return this.projectService.getProjectsByUser(userId, page)
  }
}
